//
//  XJStatus.swift
//  XJWeiBO
//
//  Created by 452608533 on 16/7/23.
//  Copyright © 2016年 452608533. All rights reserved.
//

import UIKit

class XJStatus: NSObject {
    //创建时间
    var created_at: String?
    //微博ID
    var id: Int64 = 0
    var text: String?
    //来源
    var source: String?
    //用户数据
    var user: XJUser?
    //转发微博
    var retweeted_status:XJStatus?
    //配图
    var pic_urls: [XJPictureInfo]?
    
    //转发数
    var reposts_count: Int = 0
    // 评论数
    var comments_count: Int = 0
    // 表态数
    var attitudes_count: Int = 0
    
    
    //kvc构造函数
    init(dict:[String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            //判断value是否nil  并且是否能够转成一个字典
            guard let v = value as? [String: AnyObject] else{
                return
            }
            //为其赋值
            user = XJUser(dict: v)
            
        }else if key == "retweeted_status"{
            
            guard let v = value as? [String: AnyObject] else {
                
                return
            }
            retweeted_status = XJStatus(dict: v)
            
        }else if key == "pic_urls"{
            //判断value是否为nil 并且是否能够转成一个数组
            guard let v = value as? [[String: AnyObject]] else {
                return
            }
            var tempArray: [XJPictureInfo] = [XJPictureInfo]()
            //遍历数组,字典装模型
            for dic in v {
                let pic = XJPictureInfo(dict: dic)
                tempArray.append(pic)
            }
            pic_urls = tempArray
            
        }else{
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
